VERSION 1.0 CLASS
BEGIN
  MultiUse = -1  'True
  Persistable = 0  'NotPersistable
  DataBindingBehavior = 0  'vbNone
  DataSourceBehavior  = 0  'vbNone
  MTSTransactionMode  = 0  'NotAnMTSObject
END
Attribute VB_Name = "MDBData"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = True
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = False
Attribute VB_Ext_KEY = "SavedWithClassBuilder6" ,"Yes"
Attribute VB_Ext_KEY = "Top_Level" ,"Yes"

'Connection objects
Private WithEvents cnDyn As ADODB.Connection
Attribute cnDyn.VB_VarHelpID = -1
Private WithEvents cnRO As ADODB.Connection
Attribute cnRO.VB_VarHelpID = -1

Enum WhatCon
    wcDynamic = 0
    wcReadOnly = 1
    wcAll = 9
End Enum

Private m_strProvider As String
Private m_strUserName As String
Private m_strPassword As String
Private m_strPath As String
Private m_strConnectionString As String
Private m_blnTrustedConn As Boolean

Event ConEvent(Number As Long, Description As String, ConName As String)
Event ConError(Number As Long, Source As String, Description As String)

'properties
Property Get DataPath() As String
    DataPath = m_strPath
End Property
Property Let DataPath(pstrPath As String)
    m_strPath = pstrPath
    UpdateConString
End Property
Property Get TrustedConnection() As Boolean
    TrustedConnection = m_blnTrustedConn
End Property
Property Let TrustedConnection(pTC As Boolean)
    m_blnTrustedConn = pTC
    UpdateConString
End Property
Property Get Username() As String
    Username = m_strUserName
End Property
Property Let Username(pstrUN As String)
    m_strUserName = pstrUN
    UpdateConString
End Property
Property Get Password() As String
    Password = m_strPassword
End Property
Property Let Password(pstrPW As String)
    m_strPassword = pstrPW
    UpdateConString
End Property
Property Get Provider() As String
    Provider = m_strProvider
End Property
Property Let Provider(pstrProv As String)
    m_strProvider = pstrProv
    UpdateConString
End Property
Property Get ConnectionString() As String
    ConnectionString = m_strConnectionString
End Property
Property Get conDynamic() As ADODB.Connection
    Set conDynamic = Nothing
    If cnDyn.State <> 0 Then
        Set conDynamic = cnDyn
    End If
End Property
Property Get conReadOnly() As ADODB.Connection
    Set conReadOnly = Nothing
    If cnRO.State <> 0 Then
        Set conReadOnly = cnRO
    End If
End Property

Private Sub Class_Initialize()
    Set cnDyn = New ADODB.Connection
    Set cnRO = New ADODB.Connection
'    cnDyn.CursorLocation = adUseClient
'    cnRO.CursorLocation = adUseClient
'    cnDyn.Mode = adModeShareDenyNone
'    cnRO.Mode = adModeRead
    
End Sub

Private Sub Class_Terminate()
    If Not cnDyn Is Nothing Then
        If cnDyn.State <> 0 Then cnDyn.Close
        Set cnDyn = Nothing
    End If
    If Not cnRO Is Nothing Then
        If cnRO.State <> 0 Then cnRO.Close
        Set cnRO = Nothing
    End If
End Sub

Public Function OpenConnections(wc As WhatCon) As Boolean
    On Error Resume Next
    If wc = wcAll Then
        cnDyn.Open m_strConnectionString
        cnRO.Open m_strConnectionString
    ElseIf wc = wcDynamic Then
        cnDyn.Open m_strConnectionString
    ElseIf wc = wcReadOnly Then
        cnRO.Open m_strConnectionString
    Else
        RaiseEvent ConError(glngInvalidCon, "OpenConnections", gerrInvalidCon)
    End If
    If Err.Number <> 0 Then
        RaiseEvent ConError(Err.Number, "OpenConnections", Err.Description)
        OpenConnections = False
    Else
        OpenConnections = True
    End If
    

End Function

Public Function CloseConnections(wc As WhatCon) As Boolean
    On Error Resume Next
    If wc = wcAll Then
        If cnDyn.State <> 0 Then
            cnDyn.Close
        End If
        If cnRO.State <> 0 Then
            cnRO.Close
        End If
    ElseIf wc = wcDynamic Then
        If cnDyn.State <> 0 Then
            cnDyn.Close
        End If
    ElseIf wc = wcReadOnly Then
        If cnRO.State <> 0 Then
            cnRO.Close
        End If
    Else
        RaiseEvent ConError(glngInvalidCon, "CloseConnections", gerrInvalidCon)
    End If
    If Err.Number <> 0 Then
        RaiseEvent ConError(Err.Number, "CloseConnections", Err.Description)
        CloseConnections = False
    Else
        CloseConnections = True
    End If
End Function
Private Sub UpdateConString()
    Select Case UCase(m_strProvider)
        Case "MICROSOFT.JET.OLEDB.4.0", "MICROSOFT.JET.OLEDB.4.0"   'MDB file
            m_strConnectionString = "Provider=" & m_strProvider & ";" & _
                    "Data Source=" & m_strPath & ";" & _
                    "OLE DB Services=-1;" & _
                    "User ID=" & m_strUserName & ";" & _
                    "Password=" & m_strPassword & ";"
            
            
            
            
            
            '******************************************************************************************
            'Test for Access 2000 mdb
            'm_strConnectionString = "Provider=" & m_strProvider & ";" & _
                    "OLE DB Services=-1;" & _
                    "Data Source=" & m_strPath & ";" & _
                    "Mode = readwrite" & _
                    "User ID=" & m_strUserName & ";" & _
                    "Password=" & m_strPassword & ";"

            
            'EXAMPLEs
            '"Provider=Microsoft.Jet.OLEDB.4.0;Persist Security Info=False;Data Source=" & App.Path & _
            "\MB.mdb;Mode = readwrite"

            '"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=databaseName;User ID=MyUserID;Password=MyPassword;"
            '******************************************************************************************
        
        
        
'        Case "SQLOLEDB.1", "MQIS", "{SQL SERVER}"                   'SQL Server
'            m_strConnectionString = "Provider=" & m_strProvider & ";" & _
'                    "Data Source=HM-2003;" & _
'                    "Initial Catalog=YCE;" & _
'                    "OLE DB Services=-1;"
'                    If m_blnTrustedConn Then
'                        m_strConnectionString = m_strConnectionString & _
'                            "TRUSTED_CONNECTION=Yes;"
'                    Else
'                        m_strConnectionString = m_strConnectionString & _
'                            "User ID='" & syngistic & "';" & _
'                            "Password='" & Syngistic_80631 & "';"
'                    End If
                    

          Case "SQLOLEDB.1", "MQIS", "{SQL SERVER}"                   'SQL Server
            m_strConnectionString = "Provider=SQLOLEDB.1;Password=Syngistic_80631;Persist Security Info=True;User ID=syngistic;Initial Catalog=YCE;Data Source=HM-2003"

                    
        Case "ORAOLEDB.ORACLE.1", "MSDAORA.1"                       'Oracle
            m_strConnectionString = "Provider=" & m_strProvider & ";" & _
                    "Data Source=" & m_strPath & ";" & _
                    "OLE DB Services=-1;"
                    If m_blnTrustedConn Then
                        m_strConnectionString = m_strConnectionString & _
                            "OSAuthent=1;"
                    Else
                        m_strConnectionString = m_strConnectionString & _
                            "User ID=" & m_strUserName & ";" & _
                            "Password=" & m_strPassword & ";"
                    End If
        Case Else
    End Select
End Sub


